﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace baseClass.controls
{
    public partial class emLanguageDetail : common.control.baseUserControl
    {
        private BindingSource myDataSource = null;
        public emLanguageDetail()
        {
            InitializeComponent();
            SetMaxLength();
        }

        public void SetDataSource(System.Windows.Forms.BindingSource dataSrc)
        {
            this.myDataSource = dataSrc;
            data.baseDS.emLangDataTable tbl = (data.baseDS.emLangDataTable)dataSrc.DataSource; 
            this.languageCb.DataBindings.Clear();
            this.languageCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataSrc, tbl.langCodeColumn.ColumnName, true));

            this.langLevelCb.DataBindings.Clear();
            this.langLevelCb.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataSrc, tbl.levelColumn.ColumnName, true));

            this.descriptionEd.DataBindings.Clear();
            this.descriptionEd.DataBindings.Add(new System.Windows.Forms.Binding("Text", dataSrc, tbl.descriptionColumn.ColumnName, true));
        }
        private void SetMaxLength()
        {
            data.baseDS.emLangDataTable tbl = new data.baseDS.emLangDataTable();
            descriptionEd.MaxLength = tbl.descriptionColumn.MaxLength;
        }
        public virtual void Init() 
        {
            languageCb.LoadData();
            langLevelCb.LoadData();
        }

        public virtual bool CheckData()
        {
            if (this.myDataSource.Current == null) return true;
            bool retVal = true;
            ClearNotifyError();
            if (languageCb.myValue == "") 
            {
                NotifyError(languageLbl);
                retVal = false;
            }
            if (langLevelCb.myValue == "")
            {
                NotifyError(langLevelLbl);
                retVal = false;
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            if (myDataSource.Current == null) state = true; 
            langLevelCb.Enabled = !state;
            languageCb.Enabled = !state;
            descriptionEd.ReadOnly = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            languageCb.Focus();
        }
    }
}
